package com.clkj.nangang.mvp.index.partymember;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.clkj.nangang.R;
import com.clkj.nangang.mvp.adapter.ViewPagerNewsAdapter;
import com.clkj.nangang.mvp.base.BaseActivity;
import com.clkj.nangang.mvp.index.partymember.jiandu.FragmentJiandu;
import com.clkj.nangang.mvp.index.partymember.partyhome.FragmentPartyHome;

import java.util.ArrayList;
import java.util.List;

public class PartyMemberActivity extends BaseActivity {

    private TabLayout tabPartyTitle;
    private ViewPager vpPartyPager;


    private ViewPagerNewsAdapter viewPagerNewsAdapter;
    private List<Fragment> fragmentList = new ArrayList<>();
    private List<String> mTitles = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_party_member);
        initTitle(null, null, "我是党员守规矩", true, null);
        initView();
        initData();
        assignView();
    }

    @Override
    public void initData() {
        fragmentList = new ArrayList<>();
        mTitles = new ArrayList<>();
        mTitles.add("党员之家");
        mTitles.add("干部监督");

        fragmentList.add(FragmentPartyHome.newInstance("党员之家"));
        fragmentList.add(FragmentJiandu.newInstance("干部监督"));
    }

    @Override
    public void assignView() {
        //设置TabLayout的模式
        tabPartyTitle.setTabMode(TabLayout.MODE_FIXED);

        //viewpager加载adapter
        viewPagerNewsAdapter = new ViewPagerNewsAdapter(getSupportFragmentManager(), fragmentList, mTitles);
        vpPartyPager.setAdapter(viewPagerNewsAdapter);
        vpPartyPager.setOffscreenPageLimit(2);
        //TabLayout加载viewpager
        tabPartyTitle.setupWithViewPager(vpPartyPager);
    }

    @Override
    public void initView() {

        tabPartyTitle = (TabLayout) findViewById(R.id.tab_party_title);
        vpPartyPager = (ViewPager) findViewById(R.id.vp_party_pager);
    }
}
